<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Anti-Drone Store - Professional Counter-UAV Equipment</title>
    <meta name="description" content="Professional anti-drone equipment store. High-quality counter-UAV systems, detection devices, and neutralization equipment for security professionals.">
    <meta name="keywords" content="anti-drone, counter-UAV, drone detection, drone jammer, security equipment">
    
    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    
    <!-- Common Styles -->
    <div th:replace="~{fragments/styles :: common-styles}"></div>
    <!-- Header Styles -->
    <div th:replace="~{fragments/header :: header-styles}"></div>
    
    <style>
        /* Carousel Section */
        .carousel-section {
            position: relative;
            width: 100%;
            height: 70vh;
            min-height: 500px;
            max-height: 700px;
            overflow: hidden;
            margin-bottom: 0;
        }

        .carousel-container {
            position: relative;
            width: 100%;
            height: 100%;
        }

        /* 默认内容样式 */
        .carousel-default {
            position: relative;
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .default-background {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
            animation: gradientShift 15s ease infinite;
        }

        @keyframes gradientShift {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        .default-background::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
            opacity: 0.4;
        }

        .default-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 2;
        }

        .default-content {
            position: relative;
            z-index: 3;
            text-align: center;
            color: white;
            max-width: 900px;
            padding: 20px 40px;
        }

        .default-content h1 {
            font-size: 3.5rem;
            font-weight: 800;
            margin-bottom: 20px;
            text-transform: uppercase;
            letter-spacing: 3px;
            line-height: 1.1;
            text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
            animation: fadeInDown 1s ease;
        }

        .default-content .highlight {
            color: #ffd700;
            text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
        }

        .default-content .subtitle {
            font-size: 1.1rem;
            color: rgba(255, 255, 255, 0.95);
            margin-bottom: 25px;
            max-width: 700px;
            margin-left: auto;
            margin-right: auto;
            text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.3);
            animation: fadeInUp 1s ease 0.3s both;
            line-height: 1.6;
        }

        .hero-actions {
            display: flex;
            gap: 20px;
            justify-content: center;
            margin-bottom: 30px;
            animation: fadeInUp 1s ease 0.6s both;
        }

        .hero-stats {
            display: flex;
            gap: 60px;
            justify-content: center;
            animation: fadeInUp 1s ease 0.9s both;
        }

        .stat-item {
            text-align: center;
        }

        .stat-number {
            font-size: 2rem;
            font-weight: 700;
            color: #ffd700;
            display: block;
            text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
        }

        .stat-label {
            color: rgba(255, 255, 255, 0.9);
            font-size: 0.85rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            margin-top: 5px;
        }

        /* Tech Animation */
        .tech-animation {
            position: absolute;
            right: 8%;
            top: 50%;
            transform: translateY(-50%);
            width: 300px;
            height: 300px;
            opacity: 0.25;
            z-index: 1;
        }

        .radar-circle {
            width: 100%;
            height: 100%;
            border: 2px solid rgba(255, 255, 255, 0.6);
            border-radius: 50%;
            position: relative;
            animation: rotate 15s linear infinite;
        }

        .radar-circle::before,
        .radar-circle::after {
            content: '';
            position: absolute;
            border: 1px solid rgba(255, 255, 255, 0.4);
            border-radius: 50%;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

        .radar-circle::before {
            width: 70%;
            height: 70%;
            opacity: 0.7;
        }

        .radar-circle::after {
            width: 40%;
            height: 40%;
            opacity: 0.5;
        }

        .radar-dot {
            position: absolute;
            width: 10px;
            height: 10px;
            background: rgba(255, 215, 0, 0.8);
            border-radius: 50%;
            box-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
            animation: pulse 2s infinite;
        }

        .radar-dot:nth-child(1) { top: 20%; left: 30%; animation-delay: 0s; }
        .radar-dot:nth-child(2) { top: 60%; right: 25%; animation-delay: 0.5s; }
        .radar-dot:nth-child(3) { bottom: 30%; left: 40%; animation-delay: 1s; }

        @keyframes rotate {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }

        @keyframes pulse {
            0%, 100% {
                transform: scale(1);
                opacity: 1;
            }
            50% {
                transform: scale(1.5);
                opacity: 0.5;
            }
        }

        @keyframes fadeInDown {
            from {
                opacity: 0;
                transform: translateY(-30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 轮播图样式 */
        .carousel-slide {
            position: absolute;
            width: 100%;
            height: 100%;
            opacity: 0;
            transition: opacity 1s ease-in-out;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .carousel-slide.active {
            opacity: 1;
            z-index: 1;
        }

        .carousel-slide img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .carousel-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(to top, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0.2) 50%, rgba(0, 0, 0, 0) 100%);
            display: flex;
            align-items: flex-end;
            justify-content: flex-start;
            z-index: 2;
        }

        .carousel-content {
            text-align: left;
            color: white;
            max-width: 800px;
            padding: 40px 60px;
            width: 100%;
        }

        .carousel-content h2 {
            font-size: 2.5rem;
            font-weight: 800;
            margin: 0;
            text-transform: uppercase;
            letter-spacing: 2px;
            text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.8);
            line-height: 1.2;
            position: relative;
            padding-left: 20px;
        }

        .carousel-content h2::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 5px;
            background: linear-gradient(to bottom, #ffd700, #ff6b6b);
            border-radius: 3px;
            box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
        }

        .carousel-controls {
            position: absolute;
            bottom: 30px;
            right: 60px;
            display: flex;
            gap: 10px;
            z-index: 3;
        }

        .carousel-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.5);
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .carousel-dot.active {
            background: white;
            width: 30px;
            border-radius: 6px;
        }

        .carousel-arrow {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            background: rgba(255, 255, 255, 0.3);
            color: white;
            border: none;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            cursor: pointer;
            font-size: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
            z-index: 3;
        }

        .carousel-arrow:hover {
            background: rgba(255, 255, 255, 0.5);
        }

        .carousel-arrow.prev {
            left: 30px;
        }

        .carousel-arrow.next {
            right: 30px;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .carousel-section {
                height: 60vh;
                min-height: 400px;
                max-height: 500px;
            }

            .default-content h1 {
                font-size: 2rem;
            }

            .default-content .subtitle {
                font-size: 0.9rem;
            }

            .hero-actions {
                flex-direction: column;
                gap: 10px;
            }

            .hero-actions .btn {
                width: 100%;
                max-width: 300px;
            }

            .hero-stats {
                flex-direction: row;
                gap: 20px;
                flex-wrap: wrap;
            }

            .stat-item {
                flex: 1;
                min-width: 80px;
            }

            .stat-number {
                font-size: 1.8rem;
            }

            .stat-label {
                font-size: 0.75rem;
            }

            .tech-animation {
                display: none;
            }

            .carousel-arrow {
                width: 40px;
                height: 40px;
                font-size: 20px;
            }

            .carousel-arrow.prev {
                left: 10px;
            }

            .carousel-arrow.next {
                right: 10px;
            }

            .carousel-content {
                padding: 30px 20px;
            }

            .carousel-content h2 {
                font-size: 1.5rem;
                letter-spacing: 1px;
                padding-left: 15px;
            }

            .carousel-content h2::before {
                width: 4px;
            }

            .carousel-controls {
                right: 20px;
                bottom: 20px;
            }
        }

        @media (max-width: 480px) {
            .carousel-section {
                height: 50vh;
                min-height: 350px;
                max-height: 400px;
            }

            .default-content h1 {
                font-size: 1.5rem;
            }

            .default-content .subtitle {
                font-size: 0.8rem;
            }

            .stat-number {
                font-size: 1.5rem;
            }

            .carousel-content {
                padding: 20px 15px;
            }

            .carousel-content h2 {
                font-size: 1.2rem;
                padding-left: 12px;
            }

            .carousel-content h2::before {
                width: 3px;
            }

            .carousel-controls {
                right: 15px;
                bottom: 15px;
            }
        }

        /* Featured Products */
        .featured-products {
            background: #ffffff;
            padding: 80px 0;
        }

        .featured-products .row {
            margin: 0 -20px;
        }

        .featured-products .col-4 {
            padding: 0 20px;
            margin-bottom: 40px;
        }

        .product-card {
            background: #ffffff;
            border: 1px solid rgba(0, 0, 0, 0.1);
            border-radius: 12px;
            overflow: hidden;
            transition: all 0.3s ease;
            height: 100%;
            margin-bottom: 30px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        .product-card:hover {
            transform: translateY(-10px);
            border-color: rgba(30, 58, 138, 0.3);
            box-shadow: 0 20px 40px rgba(30, 58, 138, 0.1);
        }

        /* 加载和错误状态 */
        .loading-state,
        .error-state {
            text-align: center;
            padding: 60px 20px;
            color: #64748b;
        }

        .loading-content i,
        .error-content i {
            font-size: 3rem;
            margin-bottom: 20px;
            color: #1e3a8a;
        }

        .loading-content i.fa-spin {
            color: #1e3a8a;
        }

        .error-content i {
            color: #ff4444;
        }

        .loading-content p,
        .error-content p {
            font-size: 1.1rem;
            margin-bottom: 20px;
        }
        
        .product-image {
            height: 250px;
            background: linear-gradient(135deg, #f1f5f9, #cbd5e1);
            display: flex;
            align-items: center;
            justify-content: center;
            color: #1e3a8a;
            font-size: 3rem;
            position: relative;
            overflow: hidden;
        }
        
        .product-image::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="8" height="8" patternUnits="userSpaceOnUse"><path d="M 8 0 L 0 0 0 8" fill="none" stroke="rgba(30,58,138,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
            opacity: 0.3;
        }
        
        .product-content {
            padding: 25px;
        }
        
        .product-category {
            display: inline-block;
            background: rgba(30, 58, 138, 0.2);
            color: #1e3a8a;
            padding: 4px 12px;
            border-radius: 15px;
            font-size: 0.75rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1px;
            margin-bottom: 15px;
        }
        
        .product-title {
            font-size: 1.25rem;
            font-weight: 600;
            margin-bottom: 15px;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        
        .product-price {
            font-size: 1.5rem;
            font-weight: 700;
            color: #1e3a8a;
            margin-bottom: 20px;
        }
        
        .product-description {
            color: #64748b;
            margin-bottom: 25px;
            line-height: 1.6;
            overflow: hidden;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
        }
        
        /* Features Section */
        .features {
            background: #ffffff;
        }
        
        .feature-card {
            text-align: center;
            padding: 40px 20px;
            background: #ffffff;
            border: 1px solid rgba(0, 0, 0, 0.1);
            border-radius: 12px;
            transition: all 0.3s ease;
            height: 100%;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        .feature-card:hover {
            transform: translateY(-5px);
            border-color: rgba(30, 58, 138, 0.3);
            box-shadow: 0 20px 40px rgba(30, 58, 138, 0.1);
        }
        
        .feature-icon {
            width: 80px;
            height: 80px;
            background: linear-gradient(135deg, #1e3a8a, #3b82f6);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 25px;
            color: #fff;
            font-size: 2rem;
        }
        
        .feature-title {
            font-size: 1.25rem;
            font-weight: 600;
            margin-bottom: 15px;
            text-transform: uppercase;
            letter-spacing: 1px;
            color: #1e3a8a;
        }
        
        .feature-card p {
            color: #64748b;
            line-height: 1.6;
            margin-bottom: 0;
        }
        
        /* CTA Section */
        .cta-section {
            background: linear-gradient(135deg, #f8fafc, #e2e8f0);
            text-align: center;
            position: relative;
        }
        
        .cta-section::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="15" height="15" patternUnits="userSpaceOnUse"><path d="M 15 0 L 0 0 0 15" fill="none" stroke="rgba(30,58,138,0.05)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
            opacity: 0.5;
        }
        
        .cta-content {
            position: relative;
            z-index: 2;
        }
        
        /* Responsive */
        @media (max-width: 768px) {
            .hero h1 {
                font-size: 2.5rem;
            }

            .hero .subtitle {
                font-size: 1.1rem;
            }

            .hero-stats {
                flex-direction: column;
                gap: 20px;
                text-align: center;
            }

            .tech-animation {
                display: none;
            }

            .stat-number {
                font-size: 2rem;
            }

            .featured-products .row {
                margin: 0 -10px;
            }

            .featured-products .col-4 {
                padding: 0 10px;
                margin-bottom: 30px;
                flex: 0 0 100%;
                max-width: 100%;
            }

            .product-card {
                margin-bottom: 0;
            }
        }
    </style>
</head>
<body>
    <!-- Header -->
    <div th:replace="~{fragments/header :: header}"></div>

    <!-- Carousel Section -->
    <section class="carousel-section">
        <div class="carousel-container" id="carouselContainer">
            <!-- 默认内容 - 当没有轮播图数据时显示 -->
            <div class="carousel-default" id="carouselDefault">
                <div class="default-background"></div>
                <div class="default-overlay">
                    <div class="default-content">
                        <h1>Drones Drop. Drox Stops.</h1>
                        <p class="subtitle">Welcome to assured sovereignty of the skies. Welcome to Drox. Drox is a global leader in integrated Counter-Unmanned Aerial Systems (C-UAS) technology.</p>
                        <div class="hero-actions">
                            <a href="/products" th:href="@{/products}" class="btn btn-primary btn-lg">PRODUCTS DETAILS</a>
                            <a href="/contact" th:href="@{/contact}" class="btn btn-secondary btn-lg">CONTACT US</a>
                        </div>
                        <div class="hero-stats">
                            <div class="stat-item">
                                <span class="stat-number">500+</span>
                                <div class="stat-label">Products Sold</div>
                            </div>
                            <div class="stat-item">
                                <span class="stat-number">99.9%</span>
                                <div class="stat-label">Detection Rate</div>
                            </div>
                            <div class="stat-item">
                                <span class="stat-number">24/7</span>
                                <div class="stat-label">Support</div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Tech Animation -->
                <div class="tech-animation">
                    <div class="radar-circle">
                        <div class="radar-dot"></div>
                        <div class="radar-dot"></div>
                        <div class="radar-dot"></div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 左右箭头 -->
        <button class="carousel-arrow prev" id="carouselPrev" onclick="prevSlide()" style="display: none;">‹</button>
        <button class="carousel-arrow next" id="carouselNext" onclick="nextSlide()" style="display: none;">›</button>

        <!-- 指示器 -->
        <div class="carousel-controls" id="carouselControls">
            <!-- 指示器将通过JavaScript动态生成 -->
        </div>
    </section>

    <!-- Featured Products -->
    <section class="featured-products section">
        <div class="container">
            <div class="section-title">
                <h2>FEATURED <span class="highlight">PRODUCTS</span></h2>
                <p class="section-subtitle">Discover our most popular anti-drone equipment trusted by security professionals worldwide</p>
            </div>
            
            <div class="row" id="featuredProductsContainer">
                <!-- 动态加载的特色商品将插入到这里 -->
            </div>

            <!-- 加载状态 -->
            <div class="loading-state" id="featuredLoadingState" style="display: none;">
                <div class="loading-content">
                    <i class="fas fa-spinner fa-spin"></i>
                    <p>Loading featured products...</p>
                </div>
            </div>

            <!-- 错误状态 -->
            <div class="error-state" id="featuredErrorState" style="display: none;">
                <div class="error-content">
                    <i class="fas fa-exclamation-triangle"></i>
                    <p>Failed to load featured products</p>
                    <button onclick="loadFeaturedProducts()" class="btn btn-primary btn-sm">Retry</button>
                </div>
            </div>
            
            <div class="text-center mt-5">
                <a href="/products" th:href="@{/products}" class="btn btn-secondary btn-lg">VIEW ALL PRODUCTS</a>
            </div>
        </div>
    </section>

    <!-- Features -->
    <section class="features section">
        <div class="container">
            <div class="section-title">
                <h2>WHY CHOOSE <span class="highlight">US</span></h2>
                <p class="section-subtitle">Professional-grade equipment with unmatched reliability and performance</p>
            </div>
            
            <div class="row">
                <div class="col-3">
                    <div class="feature-card">
                        <div class="feature-icon">
                            <i class="fas fa-shield-alt"></i>
                        </div>
                        <h4 class="feature-title">Military Grade</h4>
                        <p>All equipment meets military specifications for reliability and performance in critical situations.</p>
                    </div>
                </div>
                
                <div class="col-3">
                    <div class="feature-card">
                        <div class="feature-icon">
                            <i class="fas fa-shipping-fast"></i>
                        </div>
                        <h4 class="feature-title">Fast Shipping</h4>
                        <p>Express delivery worldwide with secure packaging and tracking for all orders.</p>
                    </div>
                </div>
                
                <div class="col-3">
                    <div class="feature-card">
                        <div class="feature-icon">
                            <i class="fas fa-tools"></i>
                        </div>
                        <h4 class="feature-title">Expert Support</h4>
                        <p>24/7 technical support from certified engineers and installation assistance.</p>
                    </div>
                </div>
                
                <div class="col-3">
                    <div class="feature-card">
                        <div class="feature-icon">
                            <i class="fas fa-certificate"></i>
                        </div>
                        <h4 class="feature-title">Certified Quality</h4>
                        <p>ISO certified manufacturing with comprehensive warranty and quality assurance.</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- CTA Section -->
    <section class="cta-section section">
        <div class="container">
            <div class="cta-content">
                <h2>READY TO SECURE YOUR AIRSPACE?</h2>
                <p class="section-subtitle">Get professional consultation and find the perfect anti-drone solution for your needs</p>
                <div class="mt-4">
                    <a href="/products" th:href="@{/products}" class="btn btn-primary btn-lg">BROWSE PRODUCTS</a>
                    <a href="/contact" th:href="@{/contact}" class="btn btn-secondary btn-lg">CONTACT US</a>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <div th:replace="~{fragments/footer :: footer}"></div>

    <!-- Header Scripts -->
    <div th:replace="~{fragments/header :: header-scripts}"></div>
    
    <script>
        // Smooth scrolling for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                const target = document.querySelector(this.getAttribute('href'));
                if (target) {
                    target.scrollIntoView({
                        behavior: 'smooth',
                        block: 'start'
                    });
                }
            });
        });

        // Animate elements on scroll
        const observerOptions = {
            threshold: 0.1,
            rootMargin: '0px 0px -50px 0px'
        };

        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    entry.target.classList.add('visible');
                }
            });
        }, observerOptions);

        // Initialize animations
        document.addEventListener('DOMContentLoaded', function() {
            // 加载特色商品
            loadFeaturedProducts();

            // 设置语言切换监听器
            setupLanguageChangeListener();

            const animatedElements = document.querySelectorAll('.product-card, .feature-card');
            animatedElements.forEach((element, index) => {
                element.classList.add('fade-in');
                element.style.transitionDelay = `${index * 0.1}s`;
                observer.observe(element);
            });
        });

        /**
         * 设置语言切换监听器
         */
        function setupLanguageChangeListener() {
            let currentLanguageId = localStorage.getItem('selectedLanguage') || '1';

            // 定期检查语言是否发生变化
            setInterval(() => {
                const newLanguageId = localStorage.getItem('selectedLanguage') || '1';
                if (newLanguageId !== currentLanguageId) {
                    currentLanguageId = newLanguageId;
                    console.log('语言已切换到:', newLanguageId, '重新加载特色商品');
                    loadFeaturedProducts();
                }
            }, 500);

            // 监听storage事件（跨标签页语言切换）
            window.addEventListener('storage', function(e) {
                if (e.key === 'selectedLanguage' && e.newValue !== currentLanguageId) {
                    currentLanguageId = e.newValue || '1';
                    console.log('跨标签页语言切换:', currentLanguageId);
                    loadFeaturedProducts();
                }
            });
        }

        /**
         * 加载特色商品
         */
        function loadFeaturedProducts() {
            const languageId = localStorage.getItem('selectedLanguage') || '1';
            console.log('加载特色商品，语言ID:', languageId);

            showFeaturedLoading();

            fetch(`/api/product/list?languageId=${languageId}`)
                .then(response => {
                    if (!response.ok) {
                        throw new Error(`HTTP ${response.status}: ${response.statusText}`);
                    }
                    return response.json();
                })
                .then(data => {
                    console.log('商品API响应:', data);
                    if (data.code === 200 && data.data) {
                        renderFeaturedProducts(data.data);
                    } else {
                        throw new Error(data.message || '获取商品列表失败');
                    }
                })
                .catch(error => {
                    console.error('加载特色商品失败:', error);
                    showFeaturedError();
                });
        }

        /**
         * 渲染特色商品（随机选择3个）
         */
        function renderFeaturedProducts(products) {
            const container = document.getElementById('featuredProductsContainer');

            if (!products || products.length === 0) {
                showFeaturedError();
                return;
            }

            // 随机选择3个商品
            const featuredProducts = getRandomProducts(products, 3);

            // 清空容器
            container.innerHTML = '';

            // 渲染商品卡片
            featuredProducts.forEach((product, index) => {
                const productCard = createFeaturedProductCard(product, index);
                container.appendChild(productCard);
            });

            hideFeaturedLoading();

            // 重新初始化动画
            setTimeout(() => {
                const newCards = container.querySelectorAll('.product-card');
                newCards.forEach((card, index) => {
                    card.classList.add('fade-in');
                    card.style.transitionDelay = `${index * 0.1}s`;
                    observer.observe(card);
                });
            }, 100);
        }

        /**
         * 随机选择指定数量的商品
         */
        function getRandomProducts(products, count) {
            const shuffled = [...products].sort(() => 0.5 - Math.random());
            return shuffled.slice(0, Math.min(count, products.length));
        }

        /**
         * 创建特色商品卡片
         */
        function createFeaturedProductCard(product, index) {
            const col = document.createElement('div');
            col.className = 'col-4';

            const card = document.createElement('div');
            card.className = 'product-card';

            // 获取产品图片
            const getProductImageHtml = (product) => {
                if (product.images && product.images.length > 0) {
                    const firstImage = product.images[0];
                    if (firstImage.imagePath) {
                        return `<img src="/api/file/get?filename=${firstImage.imagePath}"
                                     alt="${product.productName}"
                                     style="width: 100%; height: 100%; object-fit: cover;"
                                     onerror="this.style.display='none'; this.nextElementSibling.style.display='flex';">
                                <div style="display: none; width: 100%; height: 100%; align-items: center; justify-content: center;">
                                    <i class="fas fa-cube" style="font-size: 3rem; color: #1e3a8a;"></i>
                                </div>`;
                    }
                }

                if (product.productImage) {
                    return `<img src="/api/file/get?filename=${product.productImage}"
                                 alt="${product.productName}"
                                 style="width: 100%; height: 100%; object-fit: cover;"
                                 onerror="this.style.display='none'; this.nextElementSibling.style.display='flex';">
                            <div style="display: none; width: 100%; height: 100%; align-items: center; justify-content: center;">
                                <i class="fas fa-cube" style="font-size: 3rem; color: #1e3a8a;"></i>
                            </div>`;
                }

                return '<i class="fas fa-cube" style="font-size: 3rem; color: #1e3a8a;"></i>';
            };

            card.innerHTML = `
                <div class="product-image">
                    ${getProductImageHtml(product)}
                </div>
                <div class="product-content">
                    <div class="product-category">${product.classifyName || 'Unknown Category'}</div>
                    <h3 class="product-title">${product.productName || 'Unknown Product'}</h3>
                    <div class="product-price">Contact for Price</div>
                    <p class="product-description">${product.productInfo || 'No description available.'}</p>
                    <a href="/product/${product.id}" class="btn btn-primary">VIEW DETAILS</a>
                </div>
            `;

            col.appendChild(card);
            return col;
        }

        /**
         * 显示加载状态
         */
        function showFeaturedLoading() {
            document.getElementById('featuredLoadingState').style.display = 'block';
            document.getElementById('featuredErrorState').style.display = 'none';
            document.getElementById('featuredProductsContainer').style.opacity = '0.5';
        }

        /**
         * 隐藏加载状态
         */
        function hideFeaturedLoading() {
            document.getElementById('featuredLoadingState').style.display = 'none';
            document.getElementById('featuredProductsContainer').style.opacity = '1';
        }

        /**
         * 显示错误状态
         */
        function showFeaturedError() {
            document.getElementById('featuredLoadingState').style.display = 'none';
            document.getElementById('featuredErrorState').style.display = 'block';
            document.getElementById('featuredProductsContainer').innerHTML = '';
        }

        // ==================== 轮播图相关代码 ====================

        // 轮播图相关变量
        let currentSlide = 0;
        let carouselData = [];
        let carouselInterval = null;

        /**
         * 加载轮播图数据
         */
        function loadCarousel() {
            fetch('/api/carousel/list?status=true')
                .then(response => response.json())
                .then(data => {
                    console.log('轮播图API响应:', data);
                    if (data.code === 200 && data.data && data.data.length > 0) {
                        carouselData = data.data;
                        // 隐藏默认内容
                        const defaultContent = document.getElementById('carouselDefault');
                        if (defaultContent) {
                            defaultContent.style.display = 'none';
                        }
                        // 显示轮播图控制按钮
                        document.getElementById('carouselPrev').style.display = 'flex';
                        document.getElementById('carouselNext').style.display = 'flex';
                        // 渲染轮播图
                        renderCarousel();
                        startCarousel();
                    } else {
                        console.warn('没有可用的轮播图，显示默认内容');
                        showDefaultContent();
                    }
                })
                .catch(error => {
                    console.error('加载轮播图失败:', error);
                    showDefaultContent();
                });
        }

        /**
         * 显示默认内容
         */
        function showDefaultContent() {
            const defaultContent = document.getElementById('carouselDefault');
            if (defaultContent) {
                defaultContent.style.display = 'flex';
            }
            // 隐藏轮播图控制按钮
            document.getElementById('carouselPrev').style.display = 'none';
            document.getElementById('carouselNext').style.display = 'none';
        }

        /**
         * 渲染轮播图
         */
        function renderCarousel() {
            const container = document.getElementById('carouselContainer');
            const controls = document.getElementById('carouselControls');

            // 清空容器
            container.innerHTML = '';
            controls.innerHTML = '';

            // 渲染每个轮播图
            carouselData.forEach((item, index) => {
                // 创建轮播图项
                const slide = document.createElement('div');
                slide.className = 'carousel-slide' + (index === 0 ? ' active' : '');

                const img = document.createElement('img');
                img.src = '/api/file/get?filename=' + item.imagePath;
                img.alt = item.title || '';

                slide.appendChild(img);

                // 如果有标题或链接，添加覆盖层
                if (item.title) {
                    const overlay = document.createElement('div');
                    overlay.className = 'carousel-overlay';

                    const content = document.createElement('div');
                    content.className = 'carousel-content';

                    const title = document.createElement('h2');
                    title.textContent = item.title;
                    content.appendChild(title);

                    overlay.appendChild(content);
                    slide.appendChild(overlay);

                    // 如果有链接，添加点击事件
                    if (item.linkUrl) {
                        slide.style.cursor = 'pointer';
                        slide.onclick = function() {
                            window.location.href = item.linkUrl;
                        };
                    }
                }

                container.appendChild(slide);

                // 创建指示器
                const dot = document.createElement('div');
                dot.className = 'carousel-dot' + (index === 0 ? ' active' : '');
                dot.onclick = function() {
                    goToSlide(index);
                };
                controls.appendChild(dot);
            });
        }

        /**
         * 切换到指定幻灯片
         */
        function goToSlide(index) {
            const slides = document.querySelectorAll('.carousel-slide');
            const dots = document.querySelectorAll('.carousel-dot');

            if (slides.length === 0) return;

            // 移除当前活动状态
            slides[currentSlide].classList.remove('active');
            dots[currentSlide].classList.remove('active');

            // 设置新的活动状态
            currentSlide = index;
            slides[currentSlide].classList.add('active');
            dots[currentSlide].classList.add('active');
        }

        /**
         * 下一张
         */
        function nextSlide() {
            const nextIndex = (currentSlide + 1) % carouselData.length;
            goToSlide(nextIndex);
        }

        /**
         * 上一张
         */
        function prevSlide() {
            const prevIndex = (currentSlide - 1 + carouselData.length) % carouselData.length;
            goToSlide(prevIndex);
        }

        /**
         * 开始自动轮播
         */
        function startCarousel() {
            if (carouselData.length <= 1) return;

            // 清除之前的定时器
            if (carouselInterval) {
                clearInterval(carouselInterval);
            }

            // 每5秒切换一次
            carouselInterval = setInterval(nextSlide, 5000);
        }

        /**
         * 停止自动轮播
         */
        function stopCarousel() {
            if (carouselInterval) {
                clearInterval(carouselInterval);
                carouselInterval = null;
            }
        }

        // 页面加载时初始化轮播图
        document.addEventListener('DOMContentLoaded', function() {
            loadCarousel();

            // 鼠标悬停时暂停轮播
            const carouselSection = document.querySelector('.carousel-section');
            if (carouselSection) {
                carouselSection.addEventListener('mouseenter', stopCarousel);
                carouselSection.addEventListener('mouseleave', startCarousel);
            }
        });
    </script>
</body>
</html>
